// pages/money/money.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: true,
  },


  money: function (e) {
    if (this.data.arraa[0].extend == '已激活') {
      var id = e.currentTarget.dataset.id
      var oldmoney = e.currentTarget.dataset.money
      this.setData({
        hidden: !this.data.hidden,
        id: id,
        oldmoney: oldmoney
      })
    } else {
      console.log('您还未激活该账号！')
      wx.showModal({
        title: '',
        content: '当前账号未激活，无法充值',
      })
    }
  },
  cancelM: function (e) {
    this.setData({
      hidden: true,
    })
  },

  confirmM: function (e) {
    var that = this;

    wx.request({
      url: 'http://localhost/shopping/users_money.php',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        money: that.data.money2,
        id: that.data.id,
        oldmoney: that.data.oldmoney
      },
      success: function (res) {
        // console.log(res.data)
        that.Money();
        wx.showToast({
          title: '充值成功',
          icon: 'success',
          duration: 2000
        })
        that.setData({})
      },
      fail: function (res) {
        console.log("fail");
      }
    })

    this.setData({
      hidden: true,
      money: Number(that.data.oldmoney) + Number(that.data.money2)
    })
  },
  iMoney(e) {
    this.setData({
      money2: e.detail.value
    })
  },
  Money: function () {
    var name = getApp().globalData.usersname
    var that = this;
    wx.request({
      url: 'http://localhost/shopping/users.php',
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      data: {
        name: name
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          arraa: res.data.users,
          id: res.data.users[0].id,
          money: res.data.users[0].money
        })
      },
      fail: function (res) {
        console.log("fail");
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Money();
    this.setData({
      name: name
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})